// redux basic;
import { getSagaExtension } from 'redux-dynamic-modules-saga'
import { createStore } from 'redux-dynamic-modules'
import { getThunkExtension } from 'redux-dynamic-modules-thunk';
import makeRootReducer from './rootReducer'

// sagas
import rootSaga from '../sagas';

function getAppStateModule() {
  return {
    id: 'appState',
    reducerMap: makeRootReducer(),
    initialActions: [],
    sagas:[
      rootSaga
    ]
  };
}

function getExtensions(){
  return [
    getThunkExtension(),
    getSagaExtension()
  ];
}

export function configureStore(initialState) {
  const extensions = getExtensions();
  const module = getAppStateModule();
  return createStore({
    initialState,
    enhancers: [],
    extensions
  }, module);
}

const store = configureStore(window.___INITIAL_STATE__);

export default store;
